<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Blovex4\Controller;
use Blovex4\Logic\AdminLogic;

/**
 * 超范围服务费控制器
 * @author derek <693472824@qq.com>
 */
class ChargeController extends BaseController {

    /**
     * 获取超范围服务费
     * @author derek <693472824@qq.com>
     */
    public function index () {
        
        $list = M('Charge')->select();       
        
        $this->assign('list', $list);
        $this->display(); 
    }
    
    public function addAction(){
        
        $charge = I('charge');
        
        if(strpos($charge, '-')){
            
            list($minimum, $maximum) = explode('-', $charge);
        }
        
        $data['minimum'] = !is_numeric($minimum) ? '0' : $minimum;
        $data['maximum'] = !is_numeric($maximum) ? '0' : $maximum;
        $data['price'] = '0';
        $result = M('Charge')->add($data);
        
        if($result === false){
            $this->error('操作失败');
        }else{
            $this->success('操作成功');
        }
    }
    
    public function saveAction(){
        
        $result = array('status'=>0, 'msg'=>'', 'info'=>'');
        
        $chargeID = I('charge_id');
        $data['minimum'] = I('min');
        $data['maximum'] = I('max');
        $data['price'] = I('price');
        
        if(is_numeric($data['minimum']) && is_numeric($data['maximum']) && is_numeric($data['price'])){
            
            $re = M('Charge')->where(array('charge_id'=>$chargeID))->save($data);
            
            if($re !== false){
                $result['status'] = '1';
            }
        }
        
        $this->ajaxReturn($result);
    }
    
    public function delAction(){
        
        $chargeID = I('charge_id');
        
        $result = M('Charge')->delete($chargeID);
        
        if($result !== false){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }
    
    
}